<?php
	session_start();
	include("load-settings.php");

	if(!isset($_SESSION['user']))
		header("Location: login.php");

	$user = $_SESSION['user'];

	$result = mysql_query("SELECT * FROM user WHERE id = $user");
	$row = mysql_fetch_array($result);
	$access = $row['type'];

	if($access != 2)
		header("Location: home.php");

	$accounts = $_POST['accounts'];
	$region = mysql_real_escape_string($_POST['region']);

	$accountLines = preg_split ('/$\R?^/m', $accounts);

	$x = 0;

	$accountArray = array();

	while(isset($accountLines[$x]))
	{
		$accountBreak = explode(":", $accountLines[$x]);
		$user = mysql_real_escape_string($accountBreak[0]);
		$pass = mysql_real_escape_string($accountBreak[1]);

		$result = mysql_query("SELECT * FROM bulk_account WHERE username = '$user' AND region = '$region'");

		if(mysql_num_rows($result) == 0)
		{
			mysql_query("INSERT INTO bulk_account (username, password, region, date_added) VALUES ('$user', '$pass', '$region', ".time().")") or die(mysql_error());
		}

		$x++;
	}

	header("Location: accounts.php");
?>